<!DOCTYPE HTML>
<html>
<head>
<meta charset="UTF-8">
<title>Combined wire sizing and spacing</title>
<link rel="canonical" href="/Users/mcgrant/Repos/CVX/examples/circuit_design/html/wire_sizing_spacing.html">
<link rel="stylesheet" href="../../examples.css" type="text/css">
</head>
<body>
<div id="header">
<h1>Combined wire sizing and spacing</h1>
Jump to:&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#source">Source code</a>&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#output">Text output</a>
&nbsp;&nbsp;&nbsp;&nbsp;
<a href="#plots">Plots</a>
&nbsp;&nbsp;&nbsp;&nbsp;<a href="../../index.html">Library index</a>
</div>
<div id="content">
<a id="source"></a>
<pre class="codeinput">
<span class="comment">% Section 5.5,  L. Vandenberghe, S. Boyd, and A. El Gamal</span>
<span class="comment">% "Optimizing dominant time constant in RC circuits"</span>
<span class="comment">% Original by Lieven Vandenberghe</span>
<span class="comment">% Adapted for CVX by Joelle Skaf - 11/27/05</span>
<span class="comment">% Modified by Michael Grant - 3/8/06</span>
<span class="comment">%</span>
<span class="comment">% The problem is to determine the optimal sizes of interconnect wires and</span>
<span class="comment">% the optimal distances between them. We will consider an example with 3</span>
<span class="comment">% wires, each consisting of 5 segments (see paper, fig.21). The variables</span>
<span class="comment">% are the widths wij , and the distances s1 and s2 between the wires.</span>
<span class="comment">% The difference with the models used in other scripts is that we include a</span>
<span class="comment">% parasitic capacitance between the wires.</span>
<span class="comment">% The objective is to minimize the total width s1+s2.</span>
<span class="comment">% The problem can be formulated with the following SDP:</span>
<span class="comment">%               mimimize    s1 + s2</span>
<span class="comment">%                    s.t.   Tmax*G(w11,..,w35)-C(w11,..,w35,t11,..,t23) &gt;=0</span>
<span class="comment">%                           1/t1j &lt;= s1 - w1j - 0.5*w2j     , j = 1,..,5</span>
<span class="comment">%                           1/t2j &lt;= s2 - w3j - 0.5*w2j     , j = 1,..,5</span>
<span class="comment">%                           0 &lt;= tij &lt;= 1         , i = 1,2 , j = 1,..,5</span>
<span class="comment">%                           t1 &gt;=0, t2 &gt;= 0, s1 &gt;=smin, s2&gt;=smin</span>
<span class="comment">%                           0 &lt;= wij &lt;= wmax</span>
<span class="comment">% the 2nd and 3rd constraints are nonlinear convex constraints that can be</span>
<span class="comment">% cast as 3 x 3-LMIs (Please refer to the paper for more details).</span>

<span class="comment">%</span>
<span class="comment">% Circuit parameters</span>
<span class="comment">%</span>

n = 6;           <span class="comment">% number of nodes per wire</span>
N = 3*n;         <span class="comment">% total number of nodes</span>
m = n-1;         <span class="comment">% number of segments per wire</span>
alpha = 1;       <span class="comment">% conductance per segment is is alpha*size</span>
beta = 0.5;      <span class="comment">% capacitance per segment is twice beta*size</span>
gamma = 2;       <span class="comment">% coupling capacitance is twice gamma*distance</span>
G0 = 100;        <span class="comment">% source conductance</span>
C0 = [10,20,30]; <span class="comment">% loads of first, second, third wires</span>
wmin = 0.1;      <span class="comment">% minimum width</span>
wmax = 2.0;      <span class="comment">% maximum width</span>
smin = 1.0;      <span class="comment">% minimum distance between wires</span>
smax = 50;       <span class="comment">% upper bound on s1 and s2  (meant to be inactive)</span>

<span class="comment">%</span>
<span class="comment">% Construct the capacitance and conductance matrices</span>
<span class="comment">%   C(x) = C0 + w11 * C1 + w21 * C2 + ...</span>
<span class="comment">%   G(x) = G0 + w11 * G1 + w21 * G2 + ...</span>
<span class="comment">% and we assemble the coefficient matrices together as follows:</span>
<span class="comment">%   CC = [ C0(:) C1(:) C2(:) ... ]</span>
<span class="comment">%   GG = [ G0(:) G1(:) G2(:) ... ]</span>
<span class="comment">%</span>

CC = zeros(N,N,5*m+1);
GG = zeros(N,N,3*m+1);
<span class="keyword">for</span> w = 0 : 2,
    <span class="comment">% Constant terms</span>
    CC(w*n+n,w*n+n,1) = C0(w+1);
    GG(w*n+1,w*n+1,1) = G0;
    <span class="keyword">for</span> i = 1 : m,
        <span class="comment">% capacitances to ground</span>
        CC(w*n+[i,i+1],w*n+[i,i+1],w*m+i+1) = beta*[1,0;0,1];
        <span class="keyword">if</span> w &lt; 2,
            <span class="comment">% coupling capacitors</span>
            CC(w*n+[i,  n+i  ],w*n+[i,  n+i  ],(w+3)*m+i+1) = gamma*[1,-1;-1,1];
            CC(w*n+[i+1,n+i+1],w*n+[i+1,n+i+1],(w+3)*m+i+1) = gamma*[1,-1;-1,1];
        <span class="keyword">end</span>
        <span class="comment">% segment conductances</span>
        GG(w*n+[i,i+1],w*n+[i,i+1],w*m+i+1) = alpha*[1,-1;-1,1];
    <span class="keyword">end</span>
<span class="keyword">end</span>
<span class="comment">% Reshape for Matlab use</span>
CC = reshape(CC,N*N,5*m+1);
GG = reshape(GG,N*N,3*m+1);

<span class="comment">%</span>
<span class="comment">% Compute points the tradeoff curve and the two desired points</span>
<span class="comment">%</span>

npts    = 50;
delays  = linspace( 85, 200, npts );
xdelays = [ 130, 90 ];
xnpts   = length(xdelays);
areas   = zeros(1,npts);
xareas  = zeros(1,xnpts);
<span class="keyword">for</span> j = 1 : npts + xnpts,

    <span class="keyword">if</span> j &gt; npts,
        xj = j - npts;
        delay = xdelays(xj);
        disp( sprintf( <span class="string">'Particular solution %d of %d (Tmax = %g)'</span>, xj, xnpts, delay ) );
    <span class="keyword">else</span>,
        delay = delays(j);
        disp( sprintf( <span class="string">'Point %d of %d on the tradeoff curve (Tmax = %g)'</span>, j, npts, delay ) );
    <span class="keyword">end</span>

    <span class="comment">%</span>
    <span class="comment">% Construct and solve the convex model</span>
    <span class="comment">%</span>

    cvx_begin <span class="string">sdp</span> <span class="string">quiet</span>
        variables <span class="string">w(m,3)</span> <span class="string">t(m,2)</span> <span class="string">s(1,2)</span>
        variable <span class="string">G(N,N)</span> <span class="string">symmetric</span>
        variable <span class="string">C(N,N)</span> <span class="string">symmetric</span>
        minimize( sum(s) )
        subject <span class="string">to</span>
            G == reshape( GG * [ 1 ; w(:) ], N, N );
            C == reshape( CC * [ 1 ; w(:) ; t(:) ], N, N );
            delay * G - C &gt;= 0;
            wmin &lt;= w(:) &lt;= wmax;
            t( : ) &lt;= 1 / smin;
            s( : ) &lt;= smax;
            inv_pos( t(:,1) ) &lt;= s(1) - w(:,1) - 0.5 * w(:,2);
            inv_pos( t(:,2) ) &lt;= s(2) - w(:,3) - 0.5 * w(:,2);
    cvx_end
    ss = cvx_optval;

    <span class="keyword">if</span> j &lt;= npts,
        areas(j) = ss;
    <span class="keyword">else</span>,
        xareas(xj) = ss;

        <span class="comment">%</span>
        <span class="comment">% Draw the wires</span>
        <span class="comment">%</span>

        figure(4*xj-2);
        m2 = 2 * m;
        x1 = reshape( [ 1 : m ; 1 : m ], 1, m2 );
        x2 = x1( 1, end : -1 : 1 );
        y  = [ ss*ones(m2,1), s(2) + 0.5*w(x1,2), zeros(m2,1) ; <span class="keyword">...</span>
               ss-w(x2,1),    s(2) - 0.5*w(x2,2), w(x2,3)     ; <span class="keyword">...</span>
               ss,            s(2) + 0.5*w(1,2),  0           ];
        x1 = reshape( [ 0 : m - 1 ; 1 : m ], m2, 1 );
        x2 = x1( end : -1 : 1, 1 );
        x  = [ x1 ; x2 ; 0 ];
        hold <span class="string">off</span>;
        fill( x, y, 0.9 * ones(size(y)) );
        hold <span class="string">on</span>
        plot( x, y, <span class="string">'-'</span> );
        axis( [-0.1, m+0.1,-0.1, ss+0.1]);
        colormap(gray);
        caxis([-1,1])
        title(sprintf(<span class="string">'Solution (%d), Tmax = %g'</span>,xj,delay));

        <span class="comment">%</span>
        <span class="comment">% Build the state space models and plot step responses</span>
        <span class="comment">%</span>

        A = -inv(C)*G;
        T = linspace(0,2*delay,1000);
        B = -A * kron( eye(3), ones(n,1) );
        <span class="keyword">for</span> inp = 1 : 3,
            figure(4*xj-2+inp);
            Y1 = simple_step(A,B(:,inp),T(2),length(T));
            hold <span class="string">off</span>;
            plot(T,Y1([n,2*n,3*n],:),<span class="string">'-'</span>);
            hold <span class="string">on</span>;
            text(T(1000),Y1(  n,1000),<span class="string">'v1'</span>);
            text(T(1000),Y1(2*n,1000),<span class="string">'v2'</span>);
            text(T(1000),Y1(3*n,1000),<span class="string">'v3'</span>);
            axis([0 2*delay -0.1 1.1]);
            <span class="comment">% show dominant time constant</span>
            plot(delay*[1;1], [-0.1;1.1], <span class="string">'--'</span>);
            title(sprintf(<span class="string">'Solution (%d), Tmax = %g, step applied to wire %d'</span>,xj,delay,inp));
        <span class="keyword">end</span>

    <span class="keyword">end</span>

<span class="keyword">end</span>

<span class="comment">%</span>
<span class="comment">% Plot the tradeoff curve</span>
<span class="comment">%</span>

figure(1);
ind = isfinite(areas);
plot(areas(ind), delays(ind));
xlabel(<span class="string">'total width s_1 + s_2'</span>);
ylabel(<span class="string">'dominant time constant'</span>);
title(<span class="string">'Width-delay tradeoff curve'</span>)
hold <span class="string">on</span>;
<span class="keyword">for</span> k = 1 : xnpts,
    text( xareas(k), xdelays(k), sprintf( <span class="string">'(%d)'</span>, k ) );
<span class="keyword">end</span>
</pre>
<a id="output"></a>
<pre class="codeoutput">
Point 1 of 50 on the tradeoff curve (Tmax = 85)
Point 2 of 50 on the tradeoff curve (Tmax = 87.3469)
Point 3 of 50 on the tradeoff curve (Tmax = 89.6939)
Point 4 of 50 on the tradeoff curve (Tmax = 92.0408)
Point 5 of 50 on the tradeoff curve (Tmax = 94.3878)
Point 6 of 50 on the tradeoff curve (Tmax = 96.7347)
Point 7 of 50 on the tradeoff curve (Tmax = 99.0816)
Point 8 of 50 on the tradeoff curve (Tmax = 101.429)
Point 9 of 50 on the tradeoff curve (Tmax = 103.776)
Point 10 of 50 on the tradeoff curve (Tmax = 106.122)
Point 11 of 50 on the tradeoff curve (Tmax = 108.469)
Point 12 of 50 on the tradeoff curve (Tmax = 110.816)
Point 13 of 50 on the tradeoff curve (Tmax = 113.163)
Point 14 of 50 on the tradeoff curve (Tmax = 115.51)
Point 15 of 50 on the tradeoff curve (Tmax = 117.857)
Point 16 of 50 on the tradeoff curve (Tmax = 120.204)
Point 17 of 50 on the tradeoff curve (Tmax = 122.551)
Point 18 of 50 on the tradeoff curve (Tmax = 124.898)
Point 19 of 50 on the tradeoff curve (Tmax = 127.245)
Point 20 of 50 on the tradeoff curve (Tmax = 129.592)
Point 21 of 50 on the tradeoff curve (Tmax = 131.939)
Point 22 of 50 on the tradeoff curve (Tmax = 134.286)
Point 23 of 50 on the tradeoff curve (Tmax = 136.633)
Point 24 of 50 on the tradeoff curve (Tmax = 138.98)
Point 25 of 50 on the tradeoff curve (Tmax = 141.327)
Point 26 of 50 on the tradeoff curve (Tmax = 143.673)
Point 27 of 50 on the tradeoff curve (Tmax = 146.02)
Point 28 of 50 on the tradeoff curve (Tmax = 148.367)
Point 29 of 50 on the tradeoff curve (Tmax = 150.714)
Point 30 of 50 on the tradeoff curve (Tmax = 153.061)
Point 31 of 50 on the tradeoff curve (Tmax = 155.408)
Point 32 of 50 on the tradeoff curve (Tmax = 157.755)
Point 33 of 50 on the tradeoff curve (Tmax = 160.102)
Point 34 of 50 on the tradeoff curve (Tmax = 162.449)
Point 35 of 50 on the tradeoff curve (Tmax = 164.796)
Point 36 of 50 on the tradeoff curve (Tmax = 167.143)
Point 37 of 50 on the tradeoff curve (Tmax = 169.49)
Point 38 of 50 on the tradeoff curve (Tmax = 171.837)
Point 39 of 50 on the tradeoff curve (Tmax = 174.184)
Point 40 of 50 on the tradeoff curve (Tmax = 176.531)
Point 41 of 50 on the tradeoff curve (Tmax = 178.878)
Point 42 of 50 on the tradeoff curve (Tmax = 181.224)
Point 43 of 50 on the tradeoff curve (Tmax = 183.571)
Point 44 of 50 on the tradeoff curve (Tmax = 185.918)
Point 45 of 50 on the tradeoff curve (Tmax = 188.265)
Point 46 of 50 on the tradeoff curve (Tmax = 190.612)
Point 47 of 50 on the tradeoff curve (Tmax = 192.959)
Point 48 of 50 on the tradeoff curve (Tmax = 195.306)
Point 49 of 50 on the tradeoff curve (Tmax = 197.653)
Point 50 of 50 on the tradeoff curve (Tmax = 200)
Particular solution 1 of 2 (Tmax = 130)
Particular solution 2 of 2 (Tmax = 90)
</pre>
<a id="plots"></a>
<div id="plotoutput">
<img src="wire_sizing_spacing__01.png" alt=""> <img src="wire_sizing_spacing__02.png" alt=""> <img src="wire_sizing_spacing__03.png" alt=""> <img src="wire_sizing_spacing__04.png" alt=""> <img src="wire_sizing_spacing__05.png" alt=""> <img src="wire_sizing_spacing__06.png" alt=""> <img src="wire_sizing_spacing__07.png" alt=""> <img src="wire_sizing_spacing__08.png" alt=""> <img src="wire_sizing_spacing__09.png" alt=""> 
</div>
</div>
</body>
</html>